package com.daocao.hua.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.daocao.hua.R;
import com.daocao.hua.adapter.base.ItemAdapter;
import com.daocao.hua.model.ShareRankingModel;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class CommissionRankingRightAdapter extends ItemAdapter<ShareRankingModel.DataBean.TotalListBean, CommissionRankingRightAdapter.DefaultHolder> {

    private Context context;

    public CommissionRankingRightAdapter(Context context) {
        super(context);
        this.context = context;
    }


    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_commission_ranking, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        ShareRankingModel.DataBean.TotalListBean item = getItem(position);

        if (position == 0) {
            holder.imgRankingTop.setVisibility(View.VISIBLE);
            holder.imgRankingTop.setImageResource(R.mipmap.img_ranking_one);
            holder.txtRanking.setVisibility(View.GONE);
        } else if (position == 1) {
            holder.imgRankingTop.setVisibility(View.VISIBLE);
            holder.imgRankingTop.setImageResource(R.mipmap.img_ranking_two);
            holder.txtRanking.setVisibility(View.GONE);
        } else if (position == 2) {
            holder.imgRankingTop.setVisibility(View.VISIBLE);
            holder.imgRankingTop.setImageResource(R.mipmap.img_ranking_three);
            holder.txtRanking.setVisibility(View.GONE);
        } else {
            holder.imgRankingTop.setVisibility(View.GONE);
            holder.txtRanking.setVisibility(View.VISIBLE);
            holder.txtRanking.setText((position + 1) + "");
        }
        Glide.with(context).load(item.header).error(R.drawable.bg_default_header_sec).into(holder.imgIcon);
        holder.txtName.setText(item.real_name);
        holder.txtMoney.setText("+" + item.total_reward + "元");
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_ranking_top)
        ImageView imgRankingTop;
        @BindView(R.id.txt_ranking)
        TextView txtRanking;
        @BindView(R.id.img_icon)
        ImageView imgIcon;
        @BindView(R.id.txt_name)
        TextView txtName;
        @BindView(R.id.txt_money)
        TextView txtMoney;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
